package com.telit.uav.service.impl;

import com.alibaba.csp.sentinel.util.StringUtil;
import com.telit.uav.dao.CommUavDao;
import com.telit.uav.entity.CommUav;
import com.telit.uav.service.CommUavService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
public class CommUavServiceImpl implements CommUavService {

    @Autowired
    private CommUavDao commUavDao;


    @Override
    @Transactional
    public CommUav getUavInfoByUavCode(String uavCode) {
        CommUav commUav = commUavDao.queryUavInfoByUavCode(uavCode);
        if (commUav != null) {
            String equipmentManufacturer = commUav.getEquipmentManufacturer();
            if (StringUtil.isNotEmpty(equipmentManufacturer)) {
                String equipmentManufacturerName = commUavDao.queryNameByEquipmentManufacturerId(
                        Long.parseLong(equipmentManufacturer));
                commUav.setEquipmentManufacturer(equipmentManufacturerName);
            }
            String equipmentModel = commUav.getEquipmentModel();
            if (StringUtil.isNotEmpty(equipmentModel)) {
                String equipmentModelName = commUavDao.queryNameByEquipmentModelId(Long.parseLong(equipmentModel));
                commUav.setEquipmentModel(equipmentModelName);
            }
        }
        return commUav;
    }
}
